<?php
class TemplatesComponent extends Component {
	public $controller = null;

	public function initialize(Controller $controller) {
		$this->controller = $controller;
	}
	
	public function parse($conditions,$variables){

		$this->controller->loadModel('Template');
		if(!$this->controller->Template){
			return false;
		}
		
		$email_ = $this->controller->Template->find('first',$conditions);
		if(is_array($variables)){
			foreach ($variables as $key => $value) {
				$email_['Template']['content'] = str_replace('{'.$key.'}', $value, $email_['Template']['content']);
			}
		}
		return $email_;
	}	
}